﻿<?php
// session_start();
	
	if (!isset($_SESSION["taikhoan"]))
	{
		header("Location: ad-dangnhap.php");
	}
	include "connect.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<table width="700" align="center">
	<tr > 
	   <td height="40" align="right"><a href="ad-trangchu.php?nav=themkhoa" class="style4"><img src="image/them.png" />&nbsp; Thêm mới Khoa</a></td>
	</tr>

	<tr>
		<td>
		<!--chứa bảng tìm kiếm sinh viên -->
			<table width="700" align="center" border="0" style="border:1px solid #0066FF" cellspacing="0">
						
					  <tr> 
							<td height="25" colspan="3" align="center" bordercolor="#FFFFFF" background="image/bg_header.gif">
								<span class="style2">Tìm Khoa Cập nhật</span></td>
					  </tr>
						
						<tr bordercolor="#FFFFFF"> 
						  <td colspan="3" height="50" align="center" style="font-size:18px">
						  
								  <form name="f" method="post">
										  
											Khoa :    &nbsp;&nbsp;			
											<select name="khoa">
											    <?php
												        $sql=mysql_query("select * from khoa"); 
														while($r=mysql_fetch_row($sql))
														{
														      $makhoa=$r[0];
															  $tenkhoa=$r[1];
												?>
															  <option><?php echo " $tenkhoa"; ?></option>
												<?php 
														}
												?>
												 <option value="" selected="selected"> - Chọn Khoa</option>
											</select> &nbsp;&nbsp;
											  
										   <input name="tk" type="submit"  id="tk" value="   Tìm Kiếm  " />
								  </form>
						 </td>
					  </tr>
					  
					
			</table>
		</td>
	</tr>
</table>

<table>
     <tr>
	     <td height="30"></td>
	 </tr>
</table>

<?php
     $tenkhoa=@$_POST["khoa"];
	 if($tenkhoa!="")
	 {
			        $sql_query=mysql_query("select * from `khoa` where ten_khoa = '$tenkhoa' ");
	
				    $r=mysql_fetch_row($sql_query);
					$makhoa=$r[0];
					
				
				?>
									 <form name="f" method="post" action="" onsubmit="">
							  <table width="400" align="center" border="0" style="border:1px solid #0066FF" cellspacing="0">
									
								  <tr> 
										<td height="30" colspan="3" align="center" bordercolor="#FFFFFF" background="image/bg_header.gif">
											<span style="font-size:24px; color:#FFFFFF; font-weight:bold;">Thông tin Khoa</span></td>
								  </tr>
								  
								  <tr><td height="15" colspan="2" bordercolor="#FFFFFF"></td></tr>
									
								  <tr bordercolor="#FFFFFF" align="center"> 
									  <td  height="30" style="font-size:18px" width="200">Mã Khoa:</td>
									  <td align="left"><input type="text" name="mak" value="<?php echo $makhoa; ?>"  class="mau" readonly="" /></td>
								  </tr>
								  
								  <tr bordercolor="#FFFFFF" align="center"> 
									  <td  height="30" style="font-size:18px">Tên Khoa:</td>
									 <td align="left"><input type="text" name="tenk" value="<?php echo $tenkhoa; ?>" size="30"  /></td>
								  </tr>
								  <tr><td height="15" colspan="2" bordercolor="#FFFFFF"></td></tr>
								  
								  <tr bordercolor="#FFFFFF">
									  <td  align="right" height="30"><input type="submit" value="Cập nhật" name="cn" /></td>
									  <td align="center"><input type="reset" value="Làm Lại" name="huy" /></td>
									  <td align="left" height=""><input type="submit" value="Xóa Khoa" name="xoa"></td>
								 </tr>
								
						</table>
				  </form>	
				  
				<?php 
}
				?>  
				
<table>
     <tr>
	     <td height="30"></td>
	 </tr>
</table>	
<?php 
                if (isset($_POST["cn"]))
				{
				          $ma = $_POST["mak"];
				          $ten = $_POST["tenk"];
						  $kq = mysql_query("update `khoa` set ten_khoa = '$ten' where ma_khoa = '$ma'");
						  echo "<script type='text/javascript'>alert('Cap Nhat Thanh Cong')</script>";
		                  echo '<meta http-equiv="refresh" content="0;URL=ad-trangchu.php?nav=ttkhoa">';
						  
				}
				if (isset($_POST["xoa"]))
				{
					$ma = $_POST["mak"];
					$sql1 = mysql_query("select * from `bo mon` where ma_khoa = '$ma'");
					if (mysql_num_rows($sql1) == 0)
					{
						mysql_query("delete from khoa where ma_khoa='$ma'");
						echo "<script type='text/javascript'>alert('Xóa Thành Công')</script>";
						echo '<meta http-equiv="refresh" content="0;URL=ad-trangchu.php?nav=ttkhoa">';
					}
					else
					{
						echo "<script type='text/javascript'>alert('Không thể xóa vì có bộ môn thuộc khoa')</script>";
						echo '<meta http-equiv="refresh" content="0;URL=ad-trangchu.php?nav=ttkhoa">';
					}
				}
?>

</body>
</html>
